﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Fusion;
using Fusion.Management;
using RamGecXNAControls;
using Microsoft.Xna.Framework;
using RamGecXNAControls.ExtendedControls;
using Fusion.Content;

namespace Client.Game_States.Game_GUI_s
{
    public class MainMenuGUI
    {
        // Controls
        public GUIManager LoginManager;
        public Window LoginWindow;
        public Button ExitButton;
        public Button LoginButton;
        public Button CreditsButton;
        public Button ConnectButton;
        public Button RegisterButton;
        public TextBox UserBox;
        public TextBox PassBox;
        public Label ServerLabel;
        public CheckBox RememberBox;
        private MessageBox ErrorMessage;
        private GameTexture BorderShadow;

        // Constructor
        public MainMenuGUI()
        {
            LoginManager = new GUIManager(FusionGame.MainGame, "Themes", "Default");
            LoginManager.LoadControls(@"Content\Menus\Login.mnu");

            LoginWindow = (Window)LoginManager.GetControl("WndLogin");
            ExitButton = (Button)LoginManager.GetControl("BtnExit");
            LoginButton = (Button)LoginManager.GetControl("BtnLogin");
            CreditsButton = (Button)LoginManager.GetControl("BtnCredits");
            ConnectButton = (Button)LoginManager.GetControl("BtnConnect");
            RegisterButton = (Button)LoginManager.GetControl("BtnRegister");
            UserBox = (TextBox)LoginManager.GetControl("TxtUser");
            PassBox = (TextBox)LoginManager.GetControl("TxtPassword");
            ServerLabel = (Label)LoginManager.GetControl("LblServer");
            RememberBox = (CheckBox)LoginManager.GetControl("ChkRemember");

            LoginWindow.Bounds.Location = new Point(640 - (LoginWindow.Bounds.Width >> 1), 360 - (LoginWindow.Bounds.Height >> 1));

            ErrorMessage = new MessageBox(LoginManager, " ");
            ErrorMessage.ButtonIcon = LoginManager.Theme.IconWarning;

            BorderShadow = GFXHelper.LoadInterfaceTexture(@"BorderShade");
        }

        // Methods
        public void Update()
        {
            LoginManager.Update(FusionGame.CurrentTime);
        }
        public void Render()
        {
            FCanvas.Draw(BorderShadow, new Vector2(0, 620), Color.White);
            FCanvas.Draw(BorderShadow, Vector2.Zero, BorderShadow.Texture.Bounds, Color.White, 0f, Vector2.Zero, 1f, Microsoft.Xna.Framework.Graphics.SpriteEffects.FlipVertically, 1f);
            LoginManager.Draw(FCanvas.Batch);
        }
        public void Dispose()
        {
            LoginManager.Controls.Clear();
            BorderShadow.Release();
        }
        public void ShowError(string Message)
        {
            ErrorMessage = new MessageBox(LoginManager, Message);
            ErrorMessage.ButtonIcon = LoginManager.Theme.IconWarning;
            ErrorMessage.Show();
        }
    }
}
